package com.yegs.hospital.controller;

import com.yegs.hospital.bo.TaskRequest;
import com.yegs.hospital.common.Msg;
import com.yegs.hospital.common.PageVo;
import com.yegs.hospital.service.TaskService;
import com.yegs.hospital.vo.Task;
import com.yegs.hospital.vo.WxUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/task")
public class TaskController {

    @Autowired
    private TaskService taskService;


    @PostMapping("/list")
    public Msg list(@RequestBody TaskRequest pageParam){
        return Msg.success(taskService.list(pageParam));
    }

    @PostMapping("/save")
    public Msg save(@RequestBody Task task){
        try{
            taskService.save(task);
            return Msg.success("保存成功!");
        }catch (Exception e){
            e.printStackTrace();
            return Msg.error(e.getMessage());
        }
    }
    @GetMapping("/findAll")
    public Msg findAll(@RequestParam String openId){
        return Msg.success(taskService.findAll(openId));
    }

    @GetMapping("/findOutTime")
    public Msg findOutTime(@RequestParam String department){
        return Msg.success(taskService.findOutTime(department));
    }

    @GetMapping("/get")
    public Msg get(@RequestParam("openId") String openId){
       return Msg.success(taskService.get(openId));
    }

    @GetMapping("/getlast")
    public Msg getLast(@RequestParam("openId") String openId){
        return Msg.success(taskService.getLast(openId));
    }

    @GetMapping("/getend")
    public Msg getEnd(@RequestParam("openId") String openId){
        return Msg.success(taskService.getEnd(openId));
    }



    @GetMapping("/finishTask")
    public Msg finishTask(@RequestParam("id") Long id){
        try{
            taskService.finishTask(id);
            return Msg.success();
        }catch (Exception e){
            e.printStackTrace();
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/delete")
    public Msg delete(@RequestParam("id") Long id){
        try{
            taskService.delete(id);
            return Msg.success();
        }catch (Exception e){
            return Msg.error(e.getMessage());
        }

    }
}

